//
//  SERegistrationConfirmBtnView.swift
//  SmartEyeForPatient
//
//  Created by qdsg on 2021/4/7.
//

import UIKit

protocol SERegistrationConfirmBtnViewDelegate: NSObjectProtocol {
    func registrationConfirmBtnViewAction(view: SERegistrationConfirmBtnView)
}

class SERegistrationConfirmBtnView: UIView {

    @IBOutlet var view: UIView!
    @IBOutlet weak var confirmBtn: UIButton!

    weak var delegate: SERegistrationConfirmBtnViewDelegate?

    @IBAction func confirmBtnAction(_ sender: UIButton) {
        delegate?.registrationConfirmBtnViewAction(view: self)
    }

    var isEnable: Bool {
        get {
            return confirmBtn.isEnabled
        }
        set {
            confirmBtn.isEnabled = newValue
            if newValue {
                confirmBtn.backgroundColor = btnBgColor
            } else {
                confirmBtn.backgroundColor = btnEnableBgColor
            }
        }
    }

    var title: String? {
        get {
            return confirmBtn.titleLabel?.text
        }
        set {
            confirmBtn.setTitle(newValue, for: .normal)
        }
    }

    var titleColor: UIColor? {
        get {
            return confirmBtn.titleLabel?.textColor
        }
        set {
            confirmBtn.setTitleColor(newValue, for: .normal)
        }
    }

    var btnEnableBgColor: UIColor = Asset.border.color {
        didSet {
            if isEnable {
                confirmBtn.backgroundColor = btnBgColor
            } else {
                confirmBtn.backgroundColor = btnEnableBgColor
            }
        }
    }

    var btnBgColor: UIColor = Asset.main.color {
        didSet {
            if isEnable {
                confirmBtn.backgroundColor = btnBgColor
            } else {
                confirmBtn.backgroundColor = btnEnableBgColor
            }
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        loadNib()
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
        loadNib()
    }

    func loadNib() {
        view = UINib.init(nibName: String(describing: type(of: self)), bundle: nil).instantiate(withOwner: self, options: nil).last as? UIView
        view.frame = bounds
        confirmBtn.layer.cornerRadius = view.frame.size.height / 2.0
        confirmBtn.layer.masksToBounds = true
        confirmBtn.isIgnoreEvent = false
        addSubview(view)
    }

}
